<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ page language="java" 
	import="java.util.*, com.bean.library.Paper, com.bean.library.Subject ,com.bean.library.Option"  %>
<jsp:useBean id="partialPaper" class = "com.bean.library.Paper" scope="session"></jsp:useBean>
<jsp:useBean id="paper" class = "com.bean.library.Paper" scope="session"></jsp:useBean>
<jsp:useBean id="student" class = "com.bean.library.Student" scope="session"></jsp:useBean>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<%
	String paperTitle = partialPaper.getPaperName();
	int startIndex = partialPaper.getStartIndex();
	int prePageNum = startIndex;
	int nextPageNum = startIndex + 2;
	int curPageNum = startIndex + 1; 
	int totalSize = paper.getSubjectList().size();
	int maxPageNum = (totalSize%10==0)?(totalSize/10):(totalSize/10 + 1);
	String studentName = student.getStuName();
%>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title><%=paperTitle %></title>
    <link href="../css/paper.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" href="../css/common.css" type="text/css" />
    <script type="text/javascript" src="../scripts/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="../scripts/jquery.animate-colors-min.js"></script>
    <script type="text/javascript" src="../scripts/paper_navi.js"></script>
    <script type="text/javascript">
        $(function () {
            $("#submit_paper").hover(function () {
                $(this).animate({ backgroundColor: '#30A8F4' }, { speed: 500, queue: false });
            }, function () {
                $(this).animate({ backgroundColor: '#771347' }, { speed: 500, queue: false });
            });

            var up_hrefColor = $("#href_up").css('color');
            var down_hrefColor = $("#href_down").css('color');
            $("#page_up").hover(function () {
            	$("#submit_page_num").val(parseInt($("#page_num").val(),10)-1);
                $("#page_up_text").animate({ color: '#000000' },0);
            }, function () {
                $("#page_up_text").animate({ color: up_hrefColor }, 0);
            });

            $("#page_down").hover(function () {
            	$("#submit_page_num").val(parseInt($("#page_num").val(),10)+1);
                $("#page_down_text").animate({ color: '#000000' }, 0);
            }, function () {
                $("#page_down_text").animate({ color: down_hrefColor }, 0);
            });
            
            /**********  判断翻页      *************/
            var page_num = parseInt($("#page_num").val(),10);
            var max_page_num = parseInt($("#max_page_num").val(),10);
            
            $("#page_up").click(function(){
            	if(page_num <= 1){
            		return false;
            	}
            	$("#submit_form").submit();
            });
            $("#page_down").click(function(){
            	if(page_num >= max_page_num){
            		return false;
            	}
            	$("#submit_form").submit();
            });
            $("#submit_paper").hover(function(){
            	$("#is_submit").val('yes');
            	//$("#submit_form").attr('method','post');
            },function(){
            	$("#is_submit").val('no');
            	//$("#submit_form").attr('method','get');
            });
            $("#submit_paper").click(function(){
            	$("#submit_form").submit();
            });
        });
    </script>
</head>
<body>
<div id="bigContent">
<div id="head">
    <div id="title">
        <div class="title_left">
            <div class="titleText">Students Online Exam Platform</div>
        </div>
        <div class="title_right">
            <div class="avatar"><img src="../image/noavatar.jpg" alt="../image/noavatar.jpg"/></div>
            <div class="userState">
                <div class="userState_big"><a href="#"><%=studentName %></a></div>
                <div class="userState_small"><a href="#">logout</a></div>
            </div>
        </div>
    </div>
    <form id="navi_form" action="/Exam1/servlet/SNaviSelectServlet">
	    <div id="navi">
	        <div class="navi_top">
	            <ul class="all_navi">
	            	<li id="navi1" class="each_navi navi1">Examination</li>
	                <li id="navi2" class="each_navi navi2">Practice Test </li>
	                <li id="navi3" class="each_navi navi3">Free Q&A</li>
	            </ul>
	        </div>
	        <div class="navi_bottom">
	            <ul class="all_terms">
	            	<li class="each_term term1">freshman 1</li>
	                <li class="each_term term2">freshman 2</li>
	                <li class="each_term term3">sophomore 1</li>
	                <li class="each_term term4">sophomore 2</li>
	                <li class="each_term term5">junior 1</li>
	                <li class="each_term term6">junior 2</li>
	            </ul>
	        </div>
	    </div>
       	<input type="hidden" value="" name="test_type" id="test_type"/>
        <input type="hidden" value="" name="which_term" id="which_term"/>
    </form>
</div>
<div id="content"  class="boxShadow">
	<form id="submit_form" action="/Exam1/servlet/SubmitServlet" method="post">
	    <div id="test_title">
	        <div class="test_title_content"><%=paperTitle %></div>
	    </div>
	    <div id="problems">
	    	<%
	    		ArrayList<Subject> subList = partialPaper.getSubjectList();
				Iterator<Subject> subIt = subList.iterator();
	    		int subNum = 0;
	    		while (subIt.hasNext())
	    		{
	    			subNum++;
	    			int subNo = startIndex*10 + subNum; 
	    			Subject sub = (Subject)subIt.next();
                	ArrayList<Option> optList = sub.getOptList();
                	Iterator<Option> optIt = optList.iterator();
	    	%>
	        <div class="each_problem">
	            <div class="each_problem_title">
	                <div class="each_peoblem_no"><%=subNo+"." %></div>
	                <div class="each_problem_title_content"><%=sub.getSubjectContent() %></div>
	            </div>
	            <%if(!sub.isMulti()){ %>
	            <div class="each_problem_content_radio">
	                <ul class="each_problem_content_list">
	                <%
	    				//String subId = String.valueOf(sub.getSubjectId());
	                	
	                	int optNum = 0;
	                	while(optIt.hasNext()){
	                		char optChar = (char)(optNum+65);
	                		Option opt = (Option)optIt.next();
	                		String optId = String.valueOf(opt.getOptId());
	                		String optContent = opt.getOptContent();	                		
	                		String optValue = opt.getOptValue();
	                		String optName = opt.getOptName(); 
	                %>
	                	<li class="each_problem_content">
	                        <input id="<%=optName %>" type="radio" value="<%=optValue %>" 
	                        	name="<%=optName %>"/>
	                        <label for="<%=optName %>"><%=optChar+"."+optContent %></label>
	                    </li>
	                <%optNum++;} %>
	                </ul>
	            </div>
                <%}else{ %>
               	<div class="each_problem_content_checkbox">
	                <ul class="each_problem_content_list">
	                <% 
	                	int optNum = 0;
	                	while(optIt.hasNext()){
	                		char optChar = (char)(optNum+65);	
	                		Option opt = (Option)optIt.next();
	                		String optName = opt.getOptName();
	                		String optId = String.valueOf(opt.getOptId());
	                		String optContent = opt.getOptContent();
	                %>
	  	                <li class="each_problem_content">
	                        <input id="<%=optId %>" type="checkbox" name="<%=optName%>"/>
	                        <label for="<%=optId %>"><%=optChar+"."+optContent %></label>
	                    </li>
               		<%optNum++;} %>
		           	</ul>
	        	</div>
				<%}%>
   	 		</div>
   	 		<%} %>
   	 	</div>
	    <div id="operate">
	        <div id="page_turning">
	            <div id="page_up_down">
	                <div id="page_up">
	                    <div id="page_up_text">previous page</div>
	                </div>
	                <div id="page_down">
	                    <div id="page_down_text">next page</div>
	                </div>              
	            </div>
	            <input id="page_num" name="page_num" type="hidden" value="<%=curPageNum%>"/>
	            <input id="max_page_num" type="hidden" value="<%=maxPageNum%>"/>
	            <input id="submit_page_num" name="submit_page_num" type="hidden" value=""/> 
	            <input id="is_submit" name="is_submit" type="hidden" value="no"/>
	        </div>
	        <div id="operate_submit">
	       		<input type="button" id="submit_paper" value="Submit" />          
	        </div>
	    </div>
	</form>		    
</div>
</div>
</body>
</html>